package cn.ml.springdemo.annotation;

import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect //定义此类为切面类（保证JDK是5.0或以上版本）
public class LogDemo {
    //定义切入点
    @Pointcut("execution(* cn.ml.springdemo.annotation.F.show())")
    public void cut(){}

    //111.直接在增强上写切入点
    //@Before("execution(* cn.ml.springdemo.annotation.F.show())")
    //222.使用上方定义过的切入点
    @Before("cut()")
    public void line(){
        System.out.println("----切面@Before--------");
    }

    @AfterReturning("cut()")
    public void dot(){
        System.out.println("+++++++++++++++++");
    }

    //异常增强
    @AfterThrowing(value = "execution(* cn.ml.springdemo.annotation.F.show())",throwing = "e")
    public void error(Exception e){
        System.out.println(e.getMessage());
    }

}
